/**
 * Created by yangchen on 2017-09-11.
 */
var submit = new Vue({
    el: "#submit",
    data: {
        userName: "",
        userImg: "",
        openId: ""
    },
    methods: {
        submit: function () {
            var name = $("#name").val();
            var phone = $("#phone").val();
            if (Util.isEmpty(name)) {
                weui.alert("请输入姓名");
                return;
            }
            if (Util.isEmpty(phone)) {
                weui.alert("请输入手机号");
                return;
            }
            if (!Util.isPhone(phone)) {
                weui.alert("请输入正确的手机号");
                return;
            }
            API.save({
                name: name,
                mobile: phone,
                source: "2",
                openId: Util.getUrlParam("openId")
            }).then(function (data) {
                var callbackUrl = data.callbackUrl;
                weui.dialog({
                    title: '<i class="weui-icon-success"></i>提交成功',
                    content: '工作人员会于2日内联系您！',
                    className: 'custom-classname',
                    buttons: [{
                        label: '继续推荐',
                        type: 'primary',
                        onClick: function () {
                            location.href = callbackUrl;
                        }
                    }]
                });
            });

        },
        getParams: function () {
            API.getLeaderInfo({
                openId: Util.getUrlParam("openId")
            }).then(function (data) {
                submit.userName = data.nickName;
                submit.userImg = data.headImgUrl;
                submit.openId = data.openId;
            })
        },
        shareConfig: function() {
            API.getShareConfig({
                isWxAuth: false,
                currentUrl: location.href
            }).then(function (data) {
                wx.config({
                    debug: false,
                    appId: data.appId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareQZone']
                })
                wx.ready(function () {

                    wx.onMenuShareAppMessage({
                        title: "寻找财税分享达人", // 分享标题
                        desc: '我正在参加“寻找财税分享达人”活动，有机会获得超级福利，快来帮我增加影响力吧！', // 分享描述
                        link: "./shareRecommend.html?openId=" + Util.getCookie("openId"), // 分享链接
                        imgUrl: './img/share_1.png' // 分享图标
                    });


                    wx.onMenuShareTimeline({
                        title: '真心推荐 | 我正在参加“寻找财税分享达人”活动，快来帮我增加影响力吧！',
                        link: "./shareRecommend.html?openId=" + Util.getCookie("openId"),
                        imgUrl: './img/share_1.png'
                    });

                });
                wx.error(function (res) {
                    console.log('wx.error: ' + JSON.stringify(res));
                });
            })
        }
    },
    mounted: function () {
        this.getParams();
        this.shareConfig();
        $(document).on("click", "#recommend", function() {
            window.location = 'recommend.html';
        });
        $(document).on("click", "#share", function() {
            window.location = 'invitation.html';
        });
    },
    beforeDestroy:function () {
        $("#recommend").unbind();
        $("#share").unbind();
    }
});
